<template>
  <div class="app-container">
    <!-- “添加”等标题栏 -->
    <div class="filter-container add1">
      <el-form style="">
        <el-form-item>
          <!-- 按钮级别的控制,使用hasPerm来判断是否应该有添加这个按钮 -->
          <el-button type="primary" icon="plus" @click="showCreate" v-if="hasPerm('article:add')">添加
          </el-button>

          <!-- 下载模板 -->
          <el-button @click="exportExcel" type="primary" icon="plus" v-if="hasPerm('article:add')">下载导入模板
          </el-button>
						<!-- 使用后端导入 -->
            
            <el-button type="primary" icon="plus" v-if="hasPerm('article:add')" size="small">导入
              <input type="file" id = "btn" ref="clearFile" name = "file" @change="importf(this)" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>
          </el-button>
            
          <el-button @click="exportExcelOpertor" type="primary" icon="plus" v-if="hasPerm('article:add')" >导出</el-button>
          <el-button @click="showDisplay" type="primary" icon="plus" >显示字段</el-button>
          <!-- <el-button @click="exportExcel" type="primary" icon="plus" v-if="hasPerm('article:add')" >导出</el-button> -->
           <el-button type="danger" v-if="multipleSelectionFlag" @click="delSelect">
              批量删除
          </el-button>
          <!--
           <el-button type="primary" icon="plus" @click="showUserInfo" v-if="hasPerm('article:add')">添加
          </el-button>
          -->
        </el-form-item>
      </el-form>
      
    </div>

    <!-- “搜索”栏 -->
    <div class="searchWord">
      <!-- style="display: inline-block;"  -->
        <el-input v-model="search" 
          placeholder="请输入搜索内容" @input="inputFunction()">
        </el-input>
      </div>
    <br>
    <el-table class="tabless" :data="list" v-loading.body="listLoading" element-loading-text="拼命加载中" border fit
              highlight-current-row :row-class-name="tableRowClassName" @sort-change='sortChange' @selection-change="handleSelectionChange">
              <el-table-column
      type="selection"
      width="55"
      v-if="displayItem.select">
    </el-table-column>
      <el-table-column align="center" label="序号" width="80" v-if="displayItem.id">
        <template slot-scope="scope">
          <!-- 文章的索引 -->
          <span v-text="getIndex(scope.$index)"> </span>
          <!-- 文章的id -->
          <!-- <span v-text="scope.row.id"> </span> -->
        </template>
      </el-table-column>
      <!-- 表格主要列名称 -->
      <!-- 添加排序sortable='custom' sortable='customsss' -->
      <el-table-column align="center" prop="project_id" label="项目编号" style="width: 60px;" v-if="displayItem.code"></el-table-column>
      <el-table-column align="center" prop="project_name" label="项目名称" style="width: 60px;" v-if="displayItem.name"></el-table-column>
      <el-table-column align="center" prop="manager_id" label="项目经理" style="width: 60px;" v-if="displayItem.managerId"></el-table-column>
      <el-table-column align="center" prop="project_desc" label="项目描述" style="width: 60px;" v-if="displayItem.desc"></el-table-column>
      <el-table-column align="center" prop="committee_id" label="评审委员会编号" style="width: 60px;" v-if="displayItem.committeeId"></el-table-column>
      <el-table-column align="center" prop="start_date" label="开始日期" style="width: 60px;" v-if="displayItem.startDate"></el-table-column>
      <el-table-column align="center" prop="end_date" label="结束日期" style="width: 60px;" v-if="displayItem.endDate"></el-table-column>
      <el-table-column align="center" prop="create_staff_id" label="创建人编号" style="width: 60px;" v-if="displayItem.createStaffId"></el-table-column>
      <el-table-column align="center" label="创建时间" width="170" prop = "create_time" v-if="displayItem.createTime">
        <!-- <template slot-scope="scope">
          <span>{{scope.row.createTime}}</span>
        </template> -->
      </el-table-column>

      <el-table-column align="center" label="管理" width="350" v-if="hasPerm('article:update') & displayItem.manageMent">
        <template slot-scope="scope">
          <el-button type="primary" icon="edit" @click="showDetails(scope.$index)">详情</el-button>
          <!-- <el-button type="primary" icon="edit" @click="showProjectDetails(scope.$index)">详情</el-button> -->
          <el-button type="primary" icon="edit" @click="showUpdate(scope.$index)">修改</el-button>
          <el-button type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          <el-button type="primary" icon="edit" @click="showMember(scope.$index, scope.row)">成员</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 以上为主界面内容 -->

    <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow" >确 定</el-button>
            </span>
        </el-dialog>

        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisibleByBatch" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定批量删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisibleByBatch = false">取 消</el-button>
                <el-button type="primary" @click="delAll" >确 定</el-button>
            </span>
        </el-dialog>

        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delProjectMemberVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delProjectMemberVisible = false">取 消</el-button>
                <el-button type="primary" @click="delProjectMember" >确 定</el-button>
            </span>
        </el-dialog>
    
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNum" 
      :page-size="listQuery.pageRow"
      :total="totalCount"
      :page-sizes="[3, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper"
      class="pagination">
    </el-pagination>

    
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" >
      <el-form class="small-space" :model="tempProject" label-position="left" label-width="120px"
               style='width: 400px; margin-left:50px;'>
        
        <!-- “添加”功能弹出界面 -->
        <el-form-item label="项目名称" required v-if="dialogStatus=='create' | dialogStatus=='update'">
          <el-input type="text" v-model="tempProject.projectName" @keyup.native = "handlerproject"></el-input>
          <el-tag type="danger" v-if="this.displayInfoFromBack">{{infoFromBack}}</el-tag>          
        </el-form-item>

        <el-form-item label="项目经理" required v-if="dialogStatus=='create' | dialogStatus=='update'">
        <!-- 提供实时匹配 -->
          <el-col :span="30">
            <el-autocomplete class="inline-input" placeholder="请搜索并选择" v-model="tempProject.managerNickname" :fetch-suggestions="querySearch" @select="handleSelect"></el-autocomplete>
          </el-col>
        </el-form-item>

        <el-form-item label="项目描述" required v-if="dialogStatus=='create' | dialogStatus=='update'">
          <el-input type="textarea" v-model="tempProject.projectDesc"></el-input>
        </el-form-item>

        <el-form-item label="评审委员会名称" required v-if="dialogStatus=='create' | dialogStatus=='update'">
          <!-- 添加对话框 -->
          <el-select v-model="tempProject.committeeName" placeholder="请选择" v-if="dialogStatus=='create' | dialogStatus=='update'" :disabled="false" @change="handleSelectCommittee" style='width: 283px'>
            <el-option
              v-for="item in committeeList"
              :key="item.committee_id"
              :label="item.committee_name"
              :value="item.committee_id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开始日期" required v-if="dialogStatus=='create' | dialogStatus=='update'">
          <!-- <el-input type="text" v-model="tempProject.startDate"></el-input> -->
          <div class="block">
            <el-date-picker
              v-model="tempProject.startDate"
              type="datetime"
              placeholder="选择日期时间"
              align="right"
              @change="checkTimeStart"
              :picker-options="pickerCalendarOptions1">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="结束日期" required v-if="dialogStatus=='create' | dialogStatus=='update'">
          <!-- <el-input type="text" v-model="tempProject.endDate"></el-input> -->
          <div class="block">
            <el-date-picker
              v-model="tempProject.endDate"
              type="datetime"
              placeholder="选择日期时间"
              align="right"
              @change="checkTimeEnd"
              :picker-options="pickerCalendarOptions2">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="">
          <i class="el-icon-error" id="pro_forbit" v-if="dateError">日期填写有误，项目结束日期不能早于或等于开始日期！</i>
        </el-form-item>

        <!-- “显示字段”功能弹出界面 -->
        <div v-if="dialogStatus=='dispalyAtt'">
          <el-checkbox v-model="displayItem.select">复选框</el-checkbox><br>
          <el-checkbox v-model="displayItem.id">序号</el-checkbox><br>
          <el-checkbox v-model="displayItem.code">项目编号</el-checkbox><br>
          <el-checkbox v-model="displayItem.name">项目名称</el-checkbox><br>
          <el-checkbox v-model="displayItem.managerId">项目经理</el-checkbox><br>
          <el-checkbox v-model="displayItem.desc">项目描述</el-checkbox><br>
          <el-checkbox v-model="displayItem.committeeId">评审委员会编号</el-checkbox><br>
          <el-checkbox v-model="displayItem.startDate">开始日期</el-checkbox><br>
          <el-checkbox v-model="displayItem.endDate">结束日期</el-checkbox><br>
          <el-checkbox v-model="displayItem.createStaffId">创建人编号</el-checkbox><br>
          <el-checkbox v-model="displayItem.createTime">创建时间</el-checkbox> <br>
          <el-checkbox v-model="displayItem.manageMent">管理</el-checkbox>

        </div>        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button v-if="dialogStatus=='create'" type="success" @click="createProject" :disabled="enableCreate">创 建</el-button>
        <el-button type="primary" v-if="dialogStatus=='update'" @click="updateProject">修 改</el-button>
        
      </div>
    </el-dialog>
       
    <!-- 添加项目成员 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogAddMemberFormVisible" >
      <div>
        <el-button type="primary" @click="addNewMember">新增成员到项目[{{currrentPorject.project_name}}]</el-button>
      </div>
      <br>
      <el-table :data="projectMemberInfoList" border stripe>
        <el-table-column align="center" prop="userId" label="工号" style="width: 30px;"></el-table-column>
        <el-table-column align="center" prop="userName" label="姓名" style="width: 30px;"></el-table-column>
        <el-table-column align="center" prop="deparmentName" label="部门名称" style="width: 30px;"></el-table-column>
        <el-table-column align="center" prop="positionName" label="岗位名称" style="width: 30px;"></el-table-column>
        <el-table-column align="center" prop="proPositionName" label="项目岗位" style="width: 30px;"></el-table-column>
        <el-table-column align="center" label="管理" width="100" v-if="displayItem.id">
          <template slot-scope="scope">
            <!-- 删除 -->
            <el-button type="danger" @click="projectMemberDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogAddMemberFormVisible = false">确 定</el-button>
      </span>

    </el-dialog>

    <!-- 选择项目成员 -->
    <el-dialog :title="textMap[dialogStatusL2]" :visible.sync="dialogChooseMemberFormVisible" width="30%">
      <el-form :model="tempProjectMember" ref="projectMemberInfoList" label-width="80px">
        <el-form-item label="项目成员">
          <el-col :span="30">
            <el-autocomplete class="inline-input" placeholder="请搜索并选择" v-model="tempProjectMember.staffIdName" :fetch-suggestions="querySearch" @select="handleProjectMemberSelect"></el-autocomplete>
          </el-col>
        </el-form-item>
        <el-form-item label="员工编号">
          <el-input type="text" :disabled="true" v-model="tempProjectMember.userId"></el-input>
        </el-form-item>
        <el-form-item label="部门名称">
          <el-input type="text" :disabled="true" v-model="tempProjectMember.deparmentName"></el-input>
        </el-form-item>
        <el-form-item label="岗位名称">
          <el-input type="text" :disabled="true" v-model="tempProjectMember.positionName"></el-input>
        </el-form-item>
        <el-form-item label="项目岗位">
          <el-autocomplete class="inline-input" :disabled="enableProPositionName" v-model="tempProjectMember.projectPositionName" :fetch-suggestions="proPostionQuerySearch" @select="handleProjectPositionSelect"></el-autocomplete>
        </el-form-item>
        <el-form-item label="">
          <i class="el-icon-error" id="pro_forbit" v-if="displayError">该用户已在项目成员里，不能添加！</i>
        </el-form-item>
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogChooseMemberFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addProjectMember" :disabled="enableAddButton">添加</el-button>
      </span>
    </el-dialog>

    <!-- 项目详细信息页面 -->
    <!-- <el-dialog
      title="项目详情"
      :visible.sync="dialogProjectFormVisible"
      width="42%"
      >
      <transition name="fade" mode="out-in">
        <router-view></router-view>        
      </transition>
      
      <span slot="footer">
        <el-button @click="dialogProjectFormVisible = false">取 消</el-button>
      </span>
    </el-dialog> -->

    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible2" >
      <el-form class="small-space" :model="tempProject" label-position="left" label-width="120px"
               style='width: 400px; margin-left:50px;'>
        <el-form-item label="项目名称:">
          <i class="el-icon-pri">{{tempProject.projectName}}</i> 
        </el-form-item>
        <el-form-item label="项目经理:">
          <i class="el-icon-pri">{{tempProject.managerNickname}}</i>
        </el-form-item>
        <el-form-item label="项目描述:">
          <i class="el-icon-pri">{{tempProject.projectDesc}}</i> 
        </el-form-item>
        <el-form-item label="评审委员会名称:">
          <i class="el-icon-pri">{{tempProject.committeeName}}</i> 
        </el-form-item>
        <el-form-item label="开始日期:">
          <i class="el-icon-pri">{{tempProject.startDate}}</i> 
        </el-form-item>
        <el-form-item label="结束日期:">
          <i class="el-icon-pri">{{tempProject.endDate}}</i>          
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
      </div>
    </el-dialog>        
  </div>
</template>
<script>

  import FileSaver from "file-saver";
  import XLSX from "xlsx";
  import {mapGetters} from 'vuex';
  export default {
    data() {
      return {
          //时间选择组件开始
          pickerCalendarOptions1: {
          // shortcuts: [{
          //   text: '今天',
          //   onClick(picker) {
          //     picker.$emit('pick', new Date());
          //   }
          // }, {
          //   text: '昨天',
          //   onClick(picker) {
          //     const date = new Date();
          //     date.setTime(date.getTime() - 3600 * 1000 * 24);
          //     picker.$emit('pick', date);
          //   }
          // }, {
          //   text: '一周前',
          //   onClick(picker) {
          //     const date = new Date();
          //     date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
          //     picker.$emit('pick', date);
          //   }
          // }, {
          //   text: '明天',
          //   onClick(picker) {
          //     const date = new Date();
          //     date.setTime(date.getTime() + 3600 * 1000 * 24);
          //     picker.$emit('pick', date);
          //   }
          // }, {
          //   text: '一周后',
          //   onClick(picker) {
          //     const date = new Date();
          //     date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
          //     picker.$emit('pick', date);
          //   }
          // }],
          disabledDate: (time) => {
            if (this.tempProject.endDate != "" && this.tempProject.endDate != null) {
                return time.getTime() < Date.now() - 3600*1000*24 || time.getTime() > this.tempProject.endDate - 3600*1000*24;
            } else {
                return time.getTime() < Date.now() - 3600*1000*24;
            }
          }         
        },
        pickerCalendarOptions2: {
          disabledDate: (time) => {
            // if (this.tempProject.startDate != "" && this.tempProject.startDate != null) {
            //     return time.getTime() < Date.now() - 3600*1000*24 || time.getTime() < this.tempProject.startDate + 3600*1000*24;
            // } else {
                return time.getTime() < Date.now() - 3600*1000*24;
            // }
          }            
        },
        //时间选择组件结束

        totalCount: 0, //分页组件--数据总条数
        list: [],//表格的数据
        listLoading: false,//数据加载等待动画
        listQuery: {
          pageNum: 1,//页码
          pageRow: 5,//每页条数
          name: ''
        },
        staffList: [], //所有人员数据，用于下拉菜单(已用实时搜索替代)
        projectList: [], //所有部门数据，用于下拉菜单
        committeeList: [], //所有项目委员会数据，用于下拉菜单
        projectMemberInfoList: [], //项目成员信息（projectId, projectName, userId, userName, deparmentId, deparmentName, positionId, positionName, proPositionId, proPositionName）
        //currentProjectName: "", //
        //currentProjectId: "", //
        currrentPorject: {
          project_name: "", //
          project_id: "" //
        },
        // 为textMap中的属性,指定标题头
        dialogStatus: 'create',
        dialogStatusL2: '',
        dialogFormVisible: false,
        dialogFormVisible2: false,
        dialogAddMemberFormVisible: false,
        dialogChooseMemberFormVisible: false, //项目添加成员中，选择项目成员窗口；
        dialogProjectFormVisible: false, //项目详细信息窗口页面状态
        textMap: {
          update: '编辑',
          create: '创建项目',
          dispalyAtt: '显示字段',
          dialogAddMember: '修改项目成员',
          dialogChooseMember: '选择成员',
          details: '详细信息'
        },
        //该对象组织前端页面信息，传到后台
        tempProject: {
          //id: "",
          //content: "",
          projectId: "",
          projectName: "",
          managerId: "",
          projectDesc: "",
          committeeId: "",   //数据库操作用
          committeeName: "", //页面显示用
          startDate: "",
          endDate: "",
          managerNickname: "",
          loginUserId: ""
        },
        tempProjectMember:{
          staffIdName: "",
          userId: "", 
          userName: "", 
          //deparmentId: "", 
          deparmentName: "", 
          //positionId: "", 
          positionName: "",
          projectPositionName: "",
          projectPositionId: "",
          projectId: ""
        },
        enableAddButton: false, //人员已经在项目中，就不允许添加
        displayError: false,
        enableProPositionName: false, //人员已在项目里，不允许修改；若不在，可修改；

        dateError: false,

        delVisible:false,//删除提示弹框的状态
        delVisibleByBatch:false,//批量删除提示弹框的状态
        msg:"",//记录每一条的信息，便于取id
        delarr:[],//存放删除的数据
        multipleSelection:[],//多选的数据

        delProjectMemberVisible:false, //删除项目成员提示弹框状态
        // 搜索框中的内容
        search:'',
        // 排序的列名
        prop:'',
        // 排序的方式:包括asc,desc等
        order:'',
        // 记录导出得时候跳页的之前的页数
        temp_page:3,

        //实时匹配输入数据（实时从后台返回来的数据)
        infoFromBack:'',
        displayInfoFromBack:false, //填写表单实时查重后提示
        enableCreate:false,

        //实时搜索用户输入
        staffList2: [],
        //试试搜索用户输入的项目岗位
        projectPositions: [], //存储表“pro_position”所有岗位信息
        //state1: '',
        // 实时搜索结束 

        multipleSelectionFlag : true,
        // 记录显示字段
        displayItem:{
          select:true,
          id:true,
          code:true,
          name:true,
          desc:true,
          //managerId:flase,
          //committeeId:flase,
          //startDate:flase,
          //endDate:flase,
          //createStaffId:flase,
          //createTime:true,
          manageMent:true
        }
      }
    },
    computed: {
      ...mapGetters([
        'userId',
        'nickname'
      ])
    },
    created() {
      this.getList();
      if (this.hasPerm('user:add') || this.hasPerm('user:update')) {
        this.getAllUsers();
      }
      if (this.hasPerm('article:add') || this.hasPerm('article:update')) {
        this.getAllProjects();
        this.getAllCommittee();
        this.getAllProjectPosition();
      }
    },
    methods: {
      checkTimeStart(time){
        //开始时间不能晚于结束时间；
        console.log("start_time:", time);
        if (this.tempProject.endDate != "" && this.tempProject.endDate != null) {
            //if(time.getTime() < Date.now() - 3600*1000*24 || time.getTime() > this.tempProject.endDate - 3600*1000*24){
            //console.log(time.getTime() - this.tempProject.endDate);
            if(time.getTime() >= this.tempProject.endDate){
              console.log("Error!");
              this.dateError = true;
              this.enableCreate = true;
              return;
            }
            // else{
            //   console.log("checked..ok1..");
            // }
        } 
        // else {
        //     console.log("ooooooooookkkkkkkkkkkkkkkkk");
        // }
        this.dateError = false;
        this.enableCreate = false;
      },
      checkTimeEnd(time){
        //结束时间不能早于开始时间
        console.log("end_time:", time);
        if (this.tempProject.startDate != "" && this.tempProject.startDate != null) {
            //if(time.getTime() < Date.now() - 3600*1000*24 || time.getTime() < this.tempProject.startDate + 3600*1000*24){
            //console.log(time.getTime() - this.tempProject.startDate);
            if(time.getTime() <= this.tempProject.startDate){
              console.log("Error2!");
              this.dateError = true;
              this.enableCreate = true;
              return;
            }
            // else{
            //   console.log("checked..ok2..");
            // }
        } 
        // else {
        //     console.log("ooooooooookkkkkkkkkkkkkkkkk-----------");
        // }
        //console.log("start: ", this.tempProject.startDate);
        //console.log("end: ", this.tempProject.endDate);
        this.dateError = false;
        this.enableCreate = false;
      },
      clearFile() {
        this.$refs.clearFile.value = ''; // 清空file文件
      },
      showUserInfo(){
        console.log("id:",this.userId);
        console.log("nickname:",this.nickname);
      },
      // 导入
      importf(obj) {
        let _this = this;
        let inputDOM = this.$refs.inputer;   // 通过DOM取文件数据
        this.file = event.currentTarget.files[0];  
        var rABS = false; //是否将文件读取为二进制字符串
        var f = this.file;
        var reader = new FileReader();
        //if (!FileReader.prototype.readAsBinaryString) {
        FileReader.prototype.readAsBinaryString = function(f) {
        var binary = "";
        var rABS = false; //是否将文件读取为二进制字符串
        var pt = this;
        var wb; //读取完成的数据
        var outdata;
        var reader = new FileReader();
        reader.onload = function(e) {
              var bytes = new Uint8Array(reader.result);
              var length = bytes.byteLength;
              for(var i = 0; i < length; i++) {
                  binary += String.fromCharCode(bytes[i]);
              }
              var XLSX = require('xlsx');
              if(rABS) {
                  wb = XLSX.read(btoa(fixdata(binary)), { //手动转化
                        type: 'base64'
                  });
              } else {
                  wb = XLSX.read(binary, {
                        type: 'binary'
                  });
              }
              // outdata就是你想要的东西 excel导入的数据
              outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); 
              // excel 数据再处理
              let arr = []
              outdata.map(v => {
                  // console.log(v)
                  let obj = {}
                  obj.content = v.内容
                  obj.id = ""
                  arr.push(obj)
                  _this.tempProject = obj
                  console.log(_this.tempProject)
                  _this.createProject()
                  // this.api({
                  //   url: "/article/addArticle",
                  //   method: "post",
                  //   data: obj
                  // }).then(() => {
                  //   this.getList();
                  //   // this.dialogFormVisible = false
                  // })
              })
              _this.accountList = [...arr];
              console.log( _this.accountList)
              // _this.reload();
              // console.log('uuuuuuuuuuuuuuuuuuuuu');
            }
            alert("上传完毕！")
            _this.clearFile()
            reader.readAsArrayBuffer(f);
        }
        if(rABS) {
              reader.readAsArrayBuffer(f);
        } else {
              reader.readAsBinaryString(f);
        }
    },

      // 导入结束
    exportExcelOpertor(){
      // let tempPageSize = this.listQuery.pageRow;
      // alert(tempPageSize);
      // this.exportExcel();
      this.temp_page = this.listQuery.pageRow;
      console.log(this.totalCount)
      // this.listQuery.pageRow = this.totalCount;
      this.handleSizeChange(this.totalCount)
      // this.listQuery.pageRow = this.totalCount;
      // alert("1")
      // this.exportExcel();
      
      
      // alert("2")
      // this.exportExcel();
      window.setTimeout(this.exportExcel,50);
      // alert("3")
      // window.setTimeout("")
      window.setTimeout(this.delayTime,200);
    },
    delayTime(){
      this.listQuery.pageRow = this.temp_page
      this.generalFun();
    },
                  exportExcel () {
                    // alert("exportExcel")
                    // 设置当前日期
                    let time = new Date();
                    let year = time.getFullYear();
                    let month = time.getMonth() + 1;
                    let day = time.getDate();
                    let name = year + "" + month + "" + day;
                    // alert(this.totalCount);
                    
                    // alert(this.listQuery.pageRow);
                    // this.listQuery.pageNum = 1;
                    // this.getList();
                    // alert("zandaoguang");
                    // return
                    this.$nextTick(function () {
                        // alert("iiiiiiiiiiiiiiiii");
                        // alert(tempPageSize);
                        let wb = XLSX.utils.table_to_book(document.querySelector('.tabless'));
                        /* get binary string as output */
                        let wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: true, type: 'array'});
                        try {
                            FileSaver.saveAs(new Blob([wbout], {type: 'application/octet-stream'}), name + ".xlsx")
                        } catch (e) {
                            if (typeof console !== 'undefined') console.log(e, wbout)
                        }
                        // this.listQuery.pageRow = 3;//表格还原
                        // this.getList();
                        return wbout
                    }
                    )
                },
                
                
            inputFunction(){
              // console.log('zandaoguang');
              console.log(this.search);
              console.log(this.search == "");
              
              if(this.search){
                // console.log('aaaaaaaaaaaaaaaa');
                this.getListBySearch(this.search);
              }
              if(this.search == ""){
                this.getList();
              }
            },
            sortChange(column, prop, order) {

              // this.handleCurrentChange(1);
              this.listQuery.pageNum = 1;
              // 点击排序按钮后拿到column.order，可以发送column.order给后台，后台再根据什么排序来返回排序过后的数据
              // console.log(column);
              // console.log(column + '---' + column.prop + '---' + column.order)
              // this.prop = column.prop;
              // this.order = column.order;
              // console.log(this.prop);
              // console.log(column.prop);
              // console.log(this.order);
              // 如果搜索框中没有搜索内容
              if(this.search == ""){
                  if(column.order === "descending"){
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'DESC';
                    // this.prop = column.prop;
                    // this.order = 'DESC';
                  }else{
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'ASC';
                    // this.prop = column.prop;
                    // this.order = 'ASC';
                  }
                  if(column.prop == "content"){
                      this.getListByOrderContent();
                      // this.prop = '';
                      // this.order = '';
                  }
                  else if(column.prop == "createTime") {
                    this.getListByOrderCreateTime();
                    // this.prop = '';
                    // this.order = '';
                  }
                  else{
                    // 默认返回id排序
                    this.getList();
                  }
              }
              // 如果搜索框中有搜索内容
              else{
                  if(column.order === "descending"){
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'DESC';
                    // this.prop = column.prop;
                    // this.order = 'DESC';
                  }else{
                    this.listQuery.sortby = column.prop;
                    this.listQuery.order = 'ASC';
                    // this.prop = column.prop;
                    // this.order = 'ASC';
                  }
                  if(column.prop == "content"){
                    this.getListByContentHaveSearch();
                    // this.prop = '';
                    // this.order = '';
                  }
                  else if(column.prop == "createTime")  {
                    // 当空格的时候，应该怎么排序
                    // this.getListByOrderCreateTime();
                    // 默认按照id排序
                    // this.getListBySearch(this.search);
                    this.getListByOrderCreateTimeHaveSearch();
                    // this.prop = '';
                    // this.order = '';
                  }else{
                    // 默认什么都不做
                    // 默认返回id排序
                    this.getListBySearch(this.search);
                  }
              }
              //输出的结果 [object Object]---name---ascending
            },
            //单行删除
            handleDelete(index, row) {
              console.log("index:"+index);
              console.log(row);
                this.idx = index;
                this.msg=row;//每一条数据的记录
                this.delarr.push(this.msg.PackingId);//把单行删除的每条数据的id添加进放删除数据的数组
                this.delVisible = true;
            },
            // 当批量删除的时候,如果要是没有选中,弹出提醒
            delWarnInfo() {
              this.$message('请选择您要删除的数据');
            },
            //批量删除
            delAll() {
                // alert("我进来啦~");
                var lengths = this.multipleSelection.length;
                
                for (let i = 0; i < lengths; i++) {
                  // console.log('aaaaaaaaaaaaaaaaaaaaaaaa');
                  console.log(this.multipleSelection[i]);
                  //this.multipleSelection[i].deleteStatus = '2';
                  this.api({
                    url: "/project/deleteProject",
                    method: "post",
                    data: this.multipleSelection[i]
                }).then(() => {
                  // console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                  // if(this.search == ""){
                  //   // alert("我不空啊")
                  //   this.getList();
                  // }
                  // else{
                  //   // alert("我怎么就空了呢？")
                  //   this.getListBySearch(this.search);
                  // }
                  let msg = "删除成功";
                  this.dialogFormVisible = false;
                  this.$message({
                    message: msg,
                    type: 'success',
                    duration: 1 * 1000,
                    onClose: () => {
                      //this.getList();
                      if(this.search == ""){
                        // alert("我不空啊")
                        this.getList();
                      }
                      else{
                        // alert("我怎么就空了呢？")
                        this.getListBySearch(this.search);
                      }
                    }
                  })
                }).catch(() => {
                  this.$message.error("删除失败")
                })
                
                }
                this.delVisibleByBatch = false;//关闭删除提示模态框
            },
            
             // 确定删除
            deleteRow(){
                let _vue = this;
                // 写自己的删除的对象
                // console.log(this.delarr)
                console.log("_vue.list:");
                console.log(_vue.list);
                console.log("_vue.index:"+_vue.idx);
                let rowItem = _vue.list[_vue.idx];
                //rowItem.deleteStatus = '2';
                console.log("rowItem:");
                console.log(rowItem);
                _vue.api({
                  url: "/project/deleteProject",
                  method: "post",
                  data: rowItem
                }).then(() => {
                  console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                  // if(this.search == ""){
                  //   _vue.getList();
                  // }
                  // else{
                  //   // alert("我怎么就空了呢？")
                  //   _vue.getListBySearch(this.search);
                  // }
                  let msg = "删除成功";
                  this.dialogFormVisible = false;
                  this.$message({
                    message: msg,
                    type: 'success',
                    duration: 1 * 1000,
                    onClose: () => {
                      //this.getList();
                      if(this.search == ""){
                        _vue.getList();
                      }
                      else{
                        // alert("我怎么就空了呢？")
                        _vue.getListBySearch(this.search);
                      }
                    }
                  })
                }).catch(() => {
                  _vue.$message.error("删除失败")
                })
                // user.deleteStatus = '2';
                // _vue.api({
                //   url: "/user/updateUser",
                //   method: "post",
                //   data: user
                // }).then(() => {
                //   _vue.getList()
                // }).catch(() => {
                //   _vue.$message.error("删除失败")
                // })
                this.delVisible = false;//关闭删除提示模态框
            },
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      delSelect(){
        const length = this.multipleSelection.length;
        if(length == 0){
          this.delWarnInfo();
        }else{
          this.delVisibleByBatch = true;//显示删除弹框
        }
        // this.delAll();
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
        console.log(this.multipleSelection);
      },
      tableRowClassName({row, rowIndex}) {
        if (rowIndex % 2 === 1) {
          return 'warning-row';
        } else if (rowIndex % 2 === 0) {
          // return 'success-row';
        }
        return '';
      },

      //根据用户选择，获取委员会Id
      handleSelectCommittee(item){
        this.tempProject.committeeId = item;
        console.log("item", item);
      },
      //实时搜索输入的内容
      querySearch(queryString, cb) {
        var staffLists = this.staffList2;
        var results = queryString ? staffLists.filter(this.createFilter(queryString)) : staffLists;
        // 调用 callback 返回建议列表的数据
        console.log(results)
        cb(results);
      },
      proPostionQuerySearch(queryString, cb) {
        var tmpLists = this.projectPositions;
        var results = queryString ? tmpLists.filter(this.createFilter(queryString)) : tmpLists;
        // 调用 callback 返回建议列表的数据
        console.log(results)
        cb(results);
      },
      createFilter(queryString) {
        return (staff) => {
          return (staff.value.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
        };
      },
      handleSelect(item) {
        this.tempProject.managerId = item.userId;
        //console.log("item", item);
      },
      handlerproject(){
        console.log("gggggg");
        console.log("projectName:",this.tempProject.projectName);
        // return;
        this.api({
          url: "/project/getProjectByName",
          method: "get",
          params: this.tempProject
        }).then(data => {
          console.log("data:",data);
          if(data === "fail"){
            // alert("无效");
            this.displayInfoFromBack = true;
            this.infoFromBack = "无效";
            this.enableCreate = true;
          }
          else{
            this.displayInfoFromBack = false;
            this.infoFromBack = "";
            this.enableCreate = false;
          }
          
        })
      },
      getList() {
        //查询列表
        if (!this.hasPerm('article:list')) {
          return
        }
        this.listLoading = true;
        this.api({
          url: "/project/listProject",
          method: "get",
          params: this.listQuery
        }).then(data => {
          console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
          console.log(data)
          this.listLoading = false;
          this.list = data.list;
          this.tables = data.list;
          this.totalCount = data.totalCount;
        })
      },
      getAllUsers() {
        //获取员工列表
        this.api({
          url: "/user/list",
          method: "get"
        }).then(data => {
          console.log("allUser:",data)
          this.staffList = data.list;
          console.log('user:', this.staffList);

          //提供给实时搜索
          //console.log("data.length: ",data.list.length);
          for(var i = 0 ; i < data.list.length ; i++){
              var temp = data.list[i];
              temp['id_nickname'] = data.list[i]['userId']+'-'+data.list[i]['username'];
              //console.log('temp:', temp);
              this.staffList2.push(temp);
          }
          //console.log('staffList2:', this.staffList2);
          var json = JSON.parse(JSON.stringify(data.list).replace(/id_nickname/g,"value"));
          this.staffList2 = json;
          console.log('staffList2:', this.staffList2);
        })
      },
      getUserName(id) {
        for(var i = 0 ; i < this.staffList.length ; i++){
              if(this.staffList[i]['userId'] === id){
                 return this.staffList[i]['username'];
              }
        }
        return "";
      },
      getAllProjectPosition() {
        //获取员工列表
        this.api({
          url: "/project/projectPosition",
          method: "get"
        }).then(data => {
          console.log("allProjectPostions:",data)
          //提供给项目岗位实时搜索
          var json = JSON.parse(JSON.stringify(data.list).replace(/pro_position_name/g,"value"));
          this.projectPositions = json;
          console.log('projectPositions:', this.projectPositions);
        })
      },
      getProjectPositionName(id) {
        for(var i = 0 ; i < this.projectPositions.length ; i++){
              if(this.projectPositions[i]['pro_position_id'] === id){
                 return this.projectPositions[i]['value'];
              }
        }
        return "";
      },
      getProjectPositionId(name) {
        for(var i = 0 ; i < this.projectPositions.length ; i++){
              if(this.projectPositions[i]['value'] === name){
                 return this.projectPositions[i]['pro_position_id'];
              }
        }
        return -1;
      },
      // getUserObjById(id) {
      //   for(var i = 0 ; i < this.staffList.length ; i++){
      //         if(this.staffList[i]['userId'] === id){
      //            return this.staffList[i];
      //         }
      //   }
      //   return "";
      // },
      getCommitteeName(id) {
        for(var i = 0 ; i < this.staffList.length ; i++){
              if(this.committeeList[i]['committee_id'] === id){
                 return this.committeeList[i]['committee_name'];
              }
        }
        return "";
      },
      getAllProjects() {
        //获取部门列表
        this.api({
          url: "/project/listProject",
          method: "get"
        }).then(data => {
          this.projectList = data.list;
          console.log('projects:', this.projectList);
        })
      },
      getAllCommittee() {
        //获取委员会列表
        this.api({
          url: "/committee/listCommittee",
          method: "get"
        }).then(data => {
          this.committeeList = data.list;
          console.log('committeeList:', this.committeeList);
        })
      },
      getListByOrderContent(){
        //查询列表

        if (!this.hasPerm('article:list')) {
          return
        }
        this.listLoading = true;
        this.api({
          url: "/project/listProjectByOrder",
          method: "get",
          params: this.listQuery
        }).then(data => {
          // console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
          // console.log(data)
          this.listLoading = false;
          this.list = data.list;
          this.tables = data.list;
          this.totalCount = data.totalCount;
        })
      },

      // 当搜索框中有内容的时候，排序的时候需要只排序搜索出来的内容
      getListByContentHaveSearch(){
        //查询列表

        if (!this.hasPerm('article:list')) {
          return
        }
        this.listLoading = true;
        this.listQuery.value = this.search;
        this.api({
          url: "/project/listProjectByContentHaveSearch",
          method: "get",
          params: this.listQuery
        }).then(data => {
          console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
          console.log(data)
          this.listLoading = false;
          this.list = data.list;
          this.tables = data.list;
          this.totalCount = data.totalCount;
        })
      },

      getListByOrderCreateTimeHaveSearch(){
        //查询列表

        if (!this.hasPerm('article:list')) {
          return
        }
        this.listLoading = true;
        this.listQuery.value = this.search;
        this.api({
          url: "/project/getListByOrderCreateTimeHaveSearch",
          method: "get",
          params: this.listQuery
        }).then(data => {
          console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
          console.log(data)
          this.listLoading = false;
          this.list = data.list;
          this.tables = data.list;
          this.totalCount = data.totalCount;
        })
      },
      getListByOrderCreateTime(){
        //查询列表

        if (!this.hasPerm('article:list')) {
          return
        }
        this.listLoading = true;
        this.api({
          url: "/project/listprojectByOrderCreateTime",
          method: "get",
          params: this.listQuery
        }).then(data => {
          console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
          console.log(data)
          this.listLoading = false;
          this.list = data.list;
          this.tables = data.list;
          this.totalCount = data.totalCount;
        })
      },

      getListBySearch(val) {
        // console.log("val:"+val);
        //查询列表
        if (!this.hasPerm('article:list')) {
          return
        }
        this.listLoading = true;
        this.listQuery.value = val;
        // console.log(this.listQuery);
        this.api({
          url: "/project/listProjectBySearch",
          method: "get",
          params: this.listQuery
        }).then(data => {
          // console.log(data)
          this.listLoading = false;
          this.list = data.list;
          this.totalCount = data.totalCount;
        })
      },
      handleSizeChange(val) {
        //改变每页数量
        // alert("handleSizeChange()")
        this.listQuery.pageRow = val
        this.generalFun();
        // this.handleFilter();
      },
      handleCurrentChange(val) {
        //改变页码
        

        console.log("sortby:",this.listQuery.sortby)
        console.log("order:",this.listQuery.order)
        this.listQuery.pageNum = val
        this.generalFun();
        
      },
      getIndex($index) {
        //表格序号
        return (this.listQuery.pageNum - 1) * this.listQuery.pageRow + $index + 1
      },
      showCreate() {
        //显示新增对话框
        this.tempProject.projectName = "";
        this.tempProject.projectDesc = "";
        this.tempProject.managerNickname = "";
        this.tempProject.committeeId = ""; //测试值
        this.tempProject.committeeName = "";
        this.tempProject.startDate = "";
        this.tempProject.endDate = "";

        this.dialogStatus = "create";
        this.dialogFormVisible = true

        this.infoFromBack = '';
        this.displayInfoFromBack = false;
        this.enableCreate = false
      },
      showDisplay(){
        this.dialogStatus = "dispalyAtt"
        this.dialogFormVisible = true
      },
      //not used
      showDetails($index){
        this.dialogStatus = "details";
        this.dialogFormVisible2 = true;
        console.log($index);
        let project = this.list[$index];
        console.log(project);

        this.tempProject.projectName = project.project_name;
        this.tempProject.managerNickname = this.getUserName(project.manager_id);
        this.tempProject.projectDesc = project.project_desc;
        this.tempProject.committeeName = this.getCommitteeName(project.committee_id);
        this.tempProject.startDate = project.start_date;
        this.tempProject.endDate = project.end_date;
      },
      showProjectDetails($index) {
        this.dialogStatus = "details";
        console.log($index);
        //let project = this.projects[$index];
        let project = this.list[$index];
        console.log(project);
        
        project.status = this.dialogStatus;
        console.log('project:', project);
        // return;
        // var id = project.project_id;
        // console.log('tttttt', id);
        // this.$router.push({
        //   path: `/staff/staff/test/${id}`,
        // })

        // this.dialogProjectFormVisible = true;
        // return;
        this.$store.dispatch('SetProjectId', project).then(data => {
          this.listLoading = false
          console.log('data::::', data);
          if ("success" === data) {
            console.log('ssss');
            // this.$router.push({path: '/position/position'});
            this.$router.push({path: '/staff/staff/test'});
            this.dialogProjectFormVisible = true;
          } else {
            this.$message.error("我有点帅啊");
          }
        }).catch(() => {
          this.listLoading = false
        })
      },
      showUpdate($index) {
        //显示修改对话框
        //绑定相应的id
        this.tempProject.projectId = this.list[$index].project_id;
        //绑定相应的内容
        this.tempProject.projectName = this.list[$index].project_name;
        this.tempProject.projectDesc = this.list[$index].project_desc;
        this.tempProject.committeeId = this.list[$index].committee_id;
        this.tempProject.committeeName = this.getCommitteeName(this.list[$index].committee_id);
        this.tempProject.managerNickname = this.list[$index].manager_id+'-'+this.getUserName(this.list[$index].manager_id);
        this.tempProject.managerId = this.list[$index].manager_id;
        //TODO: time string to time format
        this.tempProject.startDate = this.list[$index].start_date;
        this.tempProject.endDate = this.list[$index].end_date;
        //console.log(this.list[$index].start_date);
        //console.log(this.list[$index].end_date);
        //this.tempProject.startDate = "2019-03-13 00:00:00";

        this.dialogStatus = "update"
        this.dialogFormVisible = true

        this.infoFromBack = '';
        this.displayInfoFromBack = false;
        this.enableCreate = false
      },
      showMember(index, row){
        console.log("index:"+index);
        console.log(row);
        this.currrentPorject.project_name = row.project_name; //显示在对话框中
        this.currrentPorject.project_id = row.project_id; //显示在对话框中
        this.projectMemberInfoList = [];

        this.tempProject.projectId = row.project_id;
        console.log("projectId: ", this.tempProject.projectId)
        this.api({
          url: "/project/getProjectMemberByID",
          method: "post",
          data: this.tempProject
        }).then(data => {
          console.log("gggggggggggggggggggggg");
          console.log(data);
          //console.log(this.projectMemberInfoList);
          console.log("aaaaaaaaaaa");
          //return 
          //合并员工部门列表，添加部门属性"deparmentNumCount"
          let set = new Set();
          for(let i=0; i<data.list.length; i++){
            if(set.has(data.list[i]["userId"])){
              for(let j=0; j<this.projectMemberInfoList.length; j++){
                if(this.projectMemberInfoList[j]["userId"] == data.list[i]["userId"]){
                  //修改​​deparmentId和​​​deparmentName为多个部门合集；同时修改deparmentNumCount字段；
                  this.projectMemberInfoList[j]["​​deparmentId"] += ";" + data.list[i]["​​deparmentId"];
                  this.projectMemberInfoList[j]["deparmentName"] +=  ";" + data.list[i]["deparmentName"];
                  this.projectMemberInfoList[j]["deparmentNumCount"] += 1;
                  break;
                }
              }
            }
            else{
              let tmp = data.list[i];
              tmp["deparmentNumCount"] = 1;
              this.projectMemberInfoList.push(tmp);
              set.add(tmp["userId"]); 
            }
          }
          //this.projectMemberInfoList = data.list;

          console.log('projectMemberInfoList:', this.projectMemberInfoList);
          //显示项目成员列表对话框
          this.dialogStatus = "dialogAddMember";
          this.dialogAddMemberFormVisible = true;
        })
      },
      //projectMemberInfoList:（projectId, projectName, userId, userName, deparmentId, deparmentName, positionId, positionName）
      checkUserIsInProject(projectId, userId){
        //console.log("this.projectMemberInfoList", this.projectMemberInfoList);
        for(let i=0; i<this.projectMemberInfoList.length; i++){
          if(this.projectMemberInfoList[i]["projectId"] === projectId){
            if(this.projectMemberInfoList[i]["userId"] === userId){
              return true;
            }
          }
        }
        return false;
      },
      getUserProjectPosition(projectId, userId){
        //console.log("this.projectMemberInfoList", this.projectMemberInfoList);
        for(let i=0; i<this.projectMemberInfoList.length; i++){
          if(this.projectMemberInfoList[i]["projectId"] === projectId){
            if(this.projectMemberInfoList[i]["userId"] === userId){
              console.log("test------", this.projectMemberInfoList[i]["proPositionName"]) 
              return this.projectMemberInfoList[i]["proPositionName"];
            }
          }
        }
        return "";
      },
  
      projectMemberDelete(index, row){
        //从项目-成员关系中删除成员
        console.log("index:"+index);
        console.log(row);
        this.idx = index;
        //this.msg = row;//每一条数据的记录
        //this.delarr.push(this.msg.PackingId);//把单行删除的每条数据的id添加进放删除数据的数组
        this.delProjectMemberVisible = true;
      },
        //确定删除
      delProjectMember(){
        console.log("this.index:"+this.idx);
        console.log("this.projectMemberInfoList", this.projectMemberInfoList)
        let rowItem = this.projectMemberInfoList[this.idx];
        console.log("rowItem:");
        console.log(rowItem);
        this.api({
          url: "/project/deleteProjectMember",
          method: "post",
          data: rowItem
        }).then(() => {
          console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
          let msg = "删除成功";
          this.currrentPorject.project_name = rowItem.projectName; //显示在对话框中
          this.delProjectMemberVisible = false;

          this.$message({
            message: msg,
            type: 'success',
            duration: 1 * 1000,
            onClose: () => {
              rowItem["project_id"] = rowItem.projectId
              this.showMember(this.idx, rowItem);
            }
          })
        }).catch(() => {
          _vue.$message.error("删除失败")
        })

        this.delProjectMemberVisible = false;//关闭删除提示模态框
      },

      //显示选择成员对话框
      addNewMember(){
        //this.dialogAddMemberFormVisible = false;
        this.dialogStatusL2 = "dialogChooseMember";
        this.dialogChooseMemberFormVisible = true;
        this.enableAddButton = false;
        this.displayError = false; 

        this.tempProjectMember.staffIdName = "";
        this.tempProjectMember.userId = "";
        this.tempProjectMember.userName = ""; 
        this.tempProjectMember.deparmentName = ""; 
        this.tempProjectMember.positionName = "";
        this.tempProjectMember.projectPositionName = "";       
        this.tempProjectMember.projectId = "";
       },
      handleProjectMemberSelect(item){
        //this.dialogStatusL2 = "dialogChooseMember";
        this.enableAddButton = false;
        this.displayError = false; 
        this.enableProPositionName = false;

        console.log("item", item);
        this.tempProjectMember.userId = item.userId;
        //所有员工信息在this.staffList中，包括：ID，姓名，部门，岗位
        //this.tempProjectMember.staffIdName = "";
        this.tempProjectMember.userName = item.username; 
        this.tempProjectMember.positionName = item.positionName;
        this.tempProjectMember.projectPositionName = this.getUserProjectPosition(this.currrentPorject.project_id, this.tempProjectMember.userId); 

        let departmentStr = "";         
        for(let i = 0; i < item.departmentList.length; i++) {
          departmentStr += item.departmentList[i]["departmentName"] + ";"
        }
        this.tempProjectMember.deparmentName = departmentStr.substr(0, departmentStr.length-1);

        //判断员工是否已经在该项目组里
        //console.log("check user list........");
        //console.log(this.currentProjectId, this.tempProjectMember.userId);
        if(this.checkUserIsInProject(this.currrentPorject.project_id, this.tempProjectMember.userId)){
          //console.log("llllllllllllllllllll")
          //员工在当前项目里
          this.enableAddButton = true;
          this.displayError = true; 
          this.enableProPositionName = true;
        }
      },
      //选择成员的项目岗位后进行的操作
      handleProjectPositionSelect(item){
        console.log("test-handleProjectPositionSelect");
        console.log("item", item);
        // this.tempProjectMember.projectPositionName = item.
        // this.tempProjectMember.projectPositionId = this.getProjectPositionId(item.);
      },
      //选择成员后，保存到数据库，关闭当前对话框，更新显示项目成员对话框；
      addProjectMember(){
        this.tempProjectMember.projectId = this.currrentPorject.project_id;
        console.log("projectID: ", this.tempProjectMember.projectId);
        console.log("projectMember: ", this.tempProjectMember.userId); 
        // console.log("projectPositionID: ", this.tempProjectMember.projectPositionId);
        console.log("projectPositionName: ", this.tempProjectMember.projectPositionName);
        this.tempProjectMember.projectPositionId = this.getProjectPositionId(this.tempProjectMember.projectPositionName);
        console.log("projectPositionID: ", this.tempProjectMember.projectPositionId);

        this.api({
          url: "/project/addProjectMember",
          method: "post",
          data: this.tempProjectMember
        }).then(() => {
          //console.log("test_20190324")
          let msg = "项目成员更新成功";
          this.dialogChooseMemberFormVisible = false;
          this.$message({
            message: msg,
            type: 'success',
            duration: 1 * 1000,
            onClose: () => {
              this.showMember(0, this.currrentPorject);
            }
          })
        })
      },
      pickerCalendarTime2DbTime(time){
        var d = new Date(time);
        var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
        return times;
      },
      createProject() {
        //创建新项目
        this.tempProject.loginUserId = this.userId;
        this.tempProject.startDate = this.pickerCalendarTime2DbTime(this.tempProject.startDate);
        this.tempProject.endDate = this.pickerCalendarTime2DbTime(this.tempProject.endDate);
        console.log("tempProject.projectName:", this.tempProject.projectName);
        console.log("tempProject.projectName:", this.tempProject);
        //console.log("tempProjecwwwwwwwwwwwwwwwwwwwwww:", this.tempProject);
        // return;
        this.api({
          url: "/project/addProject",
          method: "post",
          data: this.tempProject
        }).then(() => {
          //console.log("test_20190324")
          let msg = "添加成功";
          this.dialogFormVisible = false;
          this.$message({
            message: msg,
            type: 'success',
            duration: 1 * 1000,
            onClose: () => {
              this.getList();
            }
          })

          //this.getList();
          //this.dialogFormVisible = false
        })
      },
      updateProject() {
        this.tempProject.loginUserId = this.userId;
        console.log("tempProject:");
        console.log(this.tempProject);
        //修改文章
        this.api({
          url: "/project/updateProject",
          method: "post",
          data: this.tempProject
        }).then(() => {
          let msg = "修改成功";
          this.dialogFormVisible = false;
          this.$message({
            message: msg,
            type: 'success',
            duration: 1 * 1000,
            onClose: () => {
              this.getList();
            }
          })
        })
      },

      generalFun(){
        if(this.search){
          if(this.listQuery.sortby == "" & this.listQuery.order == ""){
            this.getListBySearch(this.search);
          }
          else if(this.listQuery.sortby == "content" && this.listQuery.order == "ASC"){
            // alert("你好啊")
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "ASC";
            this.getListByContentHaveSearch();
          }
          else if(this.listQuery.sortby == "content" && this.listQuery.order == "DESC"){
            // alert("很好啊")
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "DESC";
            this.getListByContentHaveSearch();
          }
          else if(this.listQuery.sortby == "createTime" && this.listQuery.order == "ASC"){
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "ASC";
            this.getListByOrderCreateTimeHaveSearch();
          }
          else if(this.listQuery.sortby == "createTime" && this.listQuery.order == "DESC"){
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "DESC";
            this.getListByOrderCreateTimeHaveSearch();
          }
          else{
            // ...
          }
        }
        // 没有搜索内容，所以可以直接
        else{
          // alert("ssssssssssssssssss")
          // console.log(this.prop);
          // console.log(this.order);
          if(this.listQuery.sortby == "" & this.listQuery.order == ""){
            
            this.getList();
          }
          else if(this.listQuery.sortby == "content" && this.listQuery.order == "ASC"){
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "ASC";
            // ...
            this.getListByOrderContent();
          }
          else if(this.listQuery.sortby == "content" && this.listQuery.order == "DESC"){
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "DESC";
            this.getListByOrderContent();
          }
          else if(this.listQuery.sortby == "createTime" && this.listQuery.order == "ASC"){
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "ASC";
            this.getListByOrderCreateTime();
          }
          else if(this.listQuery.sortby == "createTime" && this.listQuery.order == "DESC"){
            // this.listQuery.sortby = this.prop;
            // this.listQuery.order = "DESC";
            this.getListByOrderCreateTime();
          }else{
            // ...
            this.getList();
            // alert("我是空的！")
          }
        }
      }
    }

  }
</script>


<style>
.el-table .warning-row {
    background:whitesmoke;
    
     /* background: #ffffff; */
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  
  .pagination{
    background-color:lavender;
    margin-right: 0%;
    text-align: right;
  }

  .searchWord .add1{
    display: inline;
  }

  #btn{
            /* padding: 5px 10px;
            background: #00b0f0;
            color: #FFF;
            border: none;
            border-radius: 5px; */
        }
  #pro_forbit{
    color:red;
  }


</style>